package com.zhongge.code;

import java.util.Scanner;

/**
 * @ClassName Demo02
 * @Description TODO
 * @Author 笨忠
 * @Date 2025/9/22 23:20
 * @Version 1.0
 */
public class Demo02 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        //输入一个整数
        int n = in.nextInt();
        //输入一组数
        int[] cost = new int[n];
        for (int i = 0; i < n; i++) {
            cost[i] = in.nextInt();
        }

        //存储最低费用
        int minCost = 0;
        if (n == 1) {
            minCost = cost[0];
        }else if(n <= 3){
            if (cost[0] < cost[1]){
                if (cost[0] + cost[2] < cost[1]){
                    minCost = cost[0];
                } else {
                    minCost = cost[1];
                }
            }
        } else {
            if (cost[0] > cost[1]) {
                minCost = minCost + cost[1];//从1开始
                for (int i = 1; (i+2)<cost.length && i < cost.length; ) {
                    if (cost[i+1] < cost[i+2]){
                        minCost = minCost + cost[i+1];
                        i = i+1;
                    } else {
                        minCost = minCost + cost[i+2];
                        i = i+2;
                    }
                }
            } else {
                minCost = minCost + cost[0];
                for (int i = 0; (i+2)<cost.length && i < cost.length; ) {
                    if (cost[i+1] < cost[i+2]){
                        minCost = minCost + cost[i+1];
                        i = i+1;
                    } else {
                        minCost = minCost + cost[i+2];
                        i = i+2;
                    }
                }
            }
        }
       //最后输出最低值
        System.out.println(minCost);
    }
}
